from django.db import models

# Create your models here.


class Pic(models.Model):
    file_name = models.CharField(max_length=32, unique=True)  # 文件名，32位的md5值
    file_type = models.CharField(max_length=8)  # 文件后缀
    file_size = models.DecimalField(db_index=True, max_digits=7, decimal_places=2)  # 文件尺寸，单位 KB
    width = models.IntegerField()  # 图片宽度
    height = models.IntegerField()  # 图片高度
    resolution = models.IntegerField(db_index=True)  # 分辨率
    create_time = models.DateTimeField(auto_now_add=True)  # 创建时间
    note = models.TextField(default='')  # 备注
    rate = models.CharField(max_length=1, db_index=True, default='2')  # 评分
    pv = models.IntegerField(default=0)  # 浏览量
    info = models.JSONField(null=True)  # 记录图片其他信息

    @property
    def full_name(self):
        return '.'.join([self.file_name, self.file_type])

    @property
    def thumbnail_uri(self):
        return '/'.join(['/piclab/sm', self.file_name[0], self.full_name])

    @property
    def image_uri(self):
        return '/'.join(['/piclab/pic', self.file_name[0], self.full_name])
